import { defineStore } from 'pinia'
import { ref } from 'vue'

export const UseUserStore = defineStore(
  'user',
  () => {
    //data
    const profile = ref<any>()
    //methods
    const setProfile = (val: any) => {
      profile.value = val
    }
    //methods
    const clearProfile = () => {
      profile.value = undefined
    }
    return {
      profile,
      setProfile,
      clearProfile,
    }
  },
  {
    persist: {
      //兼容小程序的持久化存储 实现浏览器的sessionStorage
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        },
      },
    },
  },
)
